﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string module = "";
        string view = "";

        if (HttpContext.Current.Session["username"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            Control ct = null;
            if (Request.QueryString["module"] != null)
            {
                module = class_string.clear_inject(Request.QueryString["module"].ToString().Trim());
            }
            if (Request.QueryString["view"] != null)
            {
                view = HttpUtility.HtmlDecode(Request.QueryString["view"].ToString().Trim());
            }

            HtmlGenericControl gel = new HtmlGenericControl("div");

            if (module == "")
            {
                ct = Page.LoadControl("~/Controls/Template/General.ascx");
                gel.Controls.Add(ct);
                placeHolder1.Controls.Add(gel);
            }
            else if ((string)module == "logout")
            {
                Session.Clear();
                Session.Abandon();
                Response.Redirect("Login.aspx");
            }
            else
            {
                try
                {
                    ct = Page.LoadControl("~/Controls/" + module + "/" + view + ".ascx");
                    gel.Controls.Add(ct);
                    placeHolder1.Controls.Add(gel);
                }
                catch (Exception ex)
                {
                    Session["module"] = null;
                    Session["view"] = null;
                    Response.Redirect("Default");
                }
            }
        }
    }


    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string[] AutoCompleteAjaxRequest(string prefixText, int count)
    {
        List<string> listName = new List<string>();
        class_database db = new class_database();
        DataTable dt = new DataTable();
        string sql = "SELECT name FROM tbl_user WHERE name LIKE '%" + prefixText + "%'";
        dt = db.GetDataTable(sql);
        return listName.ToArray();
    }

}